/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.edu.espe.ccsoft.mantenimiento.modelos;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author misahaelfernandez
 */
@Entity
@Table(name = "ACCION")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Accion.findAll", query = "SELECT a FROM Accion a")})
public class Accion implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "COD_ACCION")
    private Integer codAccion;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 16)
    @Column(name = "NOMBRE")
    private String nombre;
    @ManyToMany(mappedBy = "accionList", fetch = FetchType.LAZY)
    private List<Rol> rolList;
    @JoinColumn(name = "COD_ACCESO", referencedColumnName = "COD_ACCESO")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Acceso acceso;

    public Accion() {
    }

    public Accion(Integer codAccion) {
        this.codAccion = codAccion;
    }

    public Accion(Integer codAccion, String nombre) {
        this.codAccion = codAccion;
        this.nombre = nombre;
    }

    public Integer getCodAccion() {
        return codAccion;
    }

    public void setCodAccion(Integer codAccion) {
        this.codAccion = codAccion;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    @XmlTransient
    public List<Rol> getRolList() {
        return rolList;
    }

    public void setRolList(List<Rol> rolList) {
        this.rolList = rolList;
    }

    public Acceso getAcceso() {
        return acceso;
    }

    public void setAcceso(Acceso acceso) {
        this.acceso = acceso;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codAccion != null ? codAccion.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Accion)) {
            return false;
        }
        Accion other = (Accion) object;
        if ((this.codAccion == null && other.codAccion != null) || (this.codAccion != null && !this.codAccion.equals(other.codAccion))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ec.edu.espe.ccsoft.mantenimiento.modelos.Accion[ codAccion=" + codAccion + " ]";
    }
    
}
